/*
 * Copyright (c) 2019 Author: Fancyears Milos Malvis @1243093366@qq.com
 * ALL COPYRIGHT REVERSED.
 */

package com.fancyears.controller;

import com.alibaba.fastjson.JSONObject;
import com.fancyears.dto.MqTestEntity;
import com.fancyears.global.GlobalSetting;
import com.fancyears.mq.producer.MessageProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Fancyears Milos Malvis
 * @Date: Created in  2019/5/31 14:58
 * @Modified By:
 */
@Controller
@RequestMapping("mq")
public class MQController {
    @Autowired
    MessageProducer producer;

    @RequestMapping(value = "/speak",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject sendMqToServer(@RequestBody MqTestEntity entity) {
        JSONObject result = new JSONObject();
        result.put(GlobalSetting.STATUS, GlobalSetting.STATUS_ENUM.OK);
        result.put(GlobalSetting.MESSAGE, "发送成功");
        switch (entity.getType()){
            case 1:
                producer.sendMessageToDirect(entity.getSpeak());
                break;
            case 2:
                producer.sendMessageToDirect2(entity.getSpeak());
                break;
        }

        return result;
    }
}
